package com.fds.app.comm.batch;

import java.util.List;
import java.util.concurrent.Callable;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fds.app.comm.context.Combuf;
import com.fds.app.comm.domain.NvProcCondDto;
import com.fds.app.comm.service.NvPostProcessor;
import com.fds.app.comm.service.NvPreProcessor;
import com.fds.app.comm.service.TrProcessInvoker;

@Component
@Scope(value="prototype")
public class ProcessIndividualTr implements Callable<String> {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private List<NvPreProcessor> nvPreProcessors;
	
	@Autowired
	private List<NvPostProcessor> nvPostProcessors;
	
	@Autowired
	private TrProcessInvoker trProcessInvoker;
	
	@Autowired
	private Combuf combuf;
	
	private NvProcCondDto nvProcCondDto;
		
	public void setNvProcCondDto(NvProcCondDto nvProcCondDto) {
		this.nvProcCondDto = nvProcCondDto;
	}

	@PostConstruct
	public void init() {
	}

	@Override
	public String call() throws Exception {
		
		combuf.setWkymd(nvProcCondDto.getWkymd());
		combuf.setImc(nvProcCondDto.getImc());
		combuf.setFund(nvProcCondDto.getFund());
		combuf.setTrno(nvProcCondDto.getTrno());
		combuf.setTableName(nvProcCondDto.getTableName());
		
		logger.info("/////////////////////////////////////////////////////////>");
		
		//운용지시 전처리 프로세스 호출
		for(NvPreProcessor nvPreProcessor : nvPreProcessors) {
			
			nvPreProcessor.init();
			
			nvPreProcessor.process();
			
			nvPreProcessor.finish();
			
		}
		
		//운용지시 정보 처리
		trProcessInvoker.invoke(combuf.getCodeJobDto().getJOB_CD());
		
		//운용지시 후처리 프로세스 호출
		for(NvPostProcessor nvPostProcessor : nvPostProcessors) {
			nvPostProcessor.init();
			
			nvPostProcessor.process();
			
			nvPostProcessor.finish();
		}
		
		logger.info("</////////////////////////////////////////////////////////");
		
		return "NULL";		
	}

}
